import React, { Component } from 'react'
import PropTypes from 'prop-types'

export default class child extends Component {
  static defaultProps = {
    count: 100
  }
  static propTypes = {
    count: PropTypes.number
  }
  constructor (props) {
    super()
    this.state = {
      count: props.count
    }
  }

  render () {
    return (
      <div>
        child
        {/* <p>{this.props.count}</p> */}
        <p>{this.state.count}</p>
        <p>
          {/* 方法一：父传子，传递函数更改父组件中的值 */}
          {/* <button
            onClick={() => {
              this.props.callback(this.props.count + 1)
            }}
          >
            change
          </button> */}
          {/* 方法二：把传递的值赋值给子组件中的模型值，然后改子组件的模型值 */}
          <button
            onClick={() => {
              this.setState({ count: this.state.count + 1 })
            }}
          >
            change
          </button>
        </p>
      </div>
    )
  }
}
